<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2019/5/21 0013
 * Describe: 基础继承类.
 */

namespace app\api\controller\efficiency;

use think\Controller;
use think\Log;
use think\Request;
use think\Db;
/*
 * 效率花呗公共控制类
 * */
class Base extends Controller
{
//    返回状态信息
    private $info = [
        0=>'成功',
        10=>'渠道标识错误',
        11=>'签名错误',
        101=>'请求超时。根据request_time参数的值，校验服务器接收到参数时的间隔时间。',
        200=>'手机号错误',
        201=>'用户已存在（撞库）',
        500=>'未知错误'
    ];
    protected $Url = 'http://fapi.51empire.com/v2/user/';
    protected $UrlOperation = [
        1=>'reg-status',//用户注册状态
        2=>'loan-apply-record',//申请贷款
        3=>'loan-status',//申请贷款结果
        4=>'repayment-status',//用户还款结果
    ];
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->selectUrl();
    }
    private function selectUrl(){
        $Url = Db::table('xb_sys_integrate')
            ->alias('sig')
            ->join('xb_sys_inteparameter sip','sig.id=sip.IntegrateID')
            ->field('sip.ParaValue')
            ->where('sig.Name="效率花呗" and sip.ParaName="lvhbUrl"')
            ->find();
        if (!empty($Url)) $this->Url = $Url['ParaValue'];
    }
    protected function info($error = false,$code = 0,$data = []){
        return json_encode([
            'error'=>$error,
            'info'=>$this->info[$code],
            'code'=>$code,
            'data'=>$data
        ]);
    }
    protected function request_post($url = '', $param = '') {
        if (empty($url) || empty($param)) {
            return false;
        }
        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);
        return $data;
    }
}
